﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain.患者移动端;
using B.S.DataBase.MyProject.ErrorCode;
using MediatR;
using MedicalPCTerminal.Read.API.Appcation.Commands.患者移动端;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace MedicalPCTerminal.Read.API.Controllers
{
    /// <summary>
    /// 患者移动端
    /// </summary>
    [Route("api/[controller]/[action]")]
    [Authorize]
    [ApiController]
    //[Authorize]
    public class PatientController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mediator">中介者</param>
        public PatientController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        [HttpGet]
        public async Task<APIResult<List<Me>>> GetMe([FromQuery]MeCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="phone">手机号</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Login(string? phone)
        {
            return Ok(phone);
        }
        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <param name="phone">手机号</param>
        /// <returns>返回字符串</returns>
        [HttpGet]
        public IActionResult GetValidateCode(string? phone)
        {
            string code = "";
            Random random = new Random();
            int num=random.Next(1000,9999);
            code=num.ToString();
            return Ok(code);
        }
        /// <summary>
        /// 登陆1
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<APIResult<Me>> Logins([FromQuery]LoginCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request, cancellationToken);
        }
    }
}
